# import socket,ssl,sys
# from flask import request,Flask
# import json

# HOST, PORT = '127.0.0.1', 4443
# REQUESTSTR="POST / HTTP/1.1\r\nHost:xx\r\nConnection: close\r\n\r\n"

# print ("Creating socket..."),
# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# print ("done.")
 
# wrappedSocket = ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_SSLv23)
 
# print ("Connecting to remote host..."),
# wrappedSocket.connect((HOST, PORT))
# print ("done.")
 
# print ("Requesting document..."),
# wrappedSocket.sendall(bytes(REQUESTSTR,encoding="utf8"))
# print ("done.")

# requestsss={'name':'李2', 'image':'img_str', 'wait':0}
# req = json.dumps(requestsss)
# wrappedSocket.send(data=req)
# while True:
#     buf = wrappedSocket.recv(4096)
#     print (buf)
#     if not buf:
#         wrappedSocket.close()
#         break

#coding:utf-8
import requests
import json
import numpy as np
import cv2
import base64
import matplotlib.pyplot as plt
from PIL import Image

requests.packages.urllib3.disable_warnings()


def getByte(path):
    with open(path, 'rb') as f:
        img_byte = base64.b64encode(f.read()) #二进制读取后变base64编码
    img_str = img_byte.decode('ascii') #转成python的unicode
    return img_str 
    
img_str = getByte('bus.jpg')#获取图像

requestsss={'name':'李2', 'image':img_str, 'wait':0}
req = json.dumps(requestsss) #字典数据结构变json(所有程序语言都认识的字符串)


res=requests.post('https://127.0.0.1:4443/',verify=False, data=req)
print(res.text)







# requestsss={'name':'李2', 'image':'img_str', 'wait':0}
# req = json.dumps(requestsss) #字典数据结构变json(所有程序语言都认识的字符串

# res=requests.post('https://127.0.0.1:4443/',verify=False, data=req) #通过内网透传分配的ip+端口
# print(res.text)

